# This file is part of the Lumenn project 
# at http://code.google.com/p/lumenn/
#
# Released under the GPLv3 at http://www.gnu.org/copyleft/gpl.html
# Designed for pygtk and the Maemo platform.
#
# Copyright 2008 by Jackson Yee (jackson@gotpossum.com)

import sys

(
	NONE,
	ERROR,
	WARNING,
	ACTION,	# Debugging units
	TRACE,	# Debugging functions
	ALL,
)	=	xrange(0, 6)

# *********************************************************************
class StdoutLog(object):
	@classmethod
	def write(self, msg):
		sys.stdout.write(str(msg))
		sys.stdout.write('\n')
		
# *********************************************************************
class NullLog(object):
	@classmethod
	def write(self, msg):
		pass

# *********************************************************************
class FileLog(object):
	def __init__(self, filename):
		self.f = file(filename, 'a+')
	
	def write(self, msg):
		self.f.write(str(msg))
		self.f.write('\n')

# *********************************************************************
class MemLog(object):
	lines = []
	
	@classmethod
	def write(self, msg):
		lines.append( str(msg) )

log 			= StdoutLog
loglevel	=	ACTION

# ====================================================================
def SetLog(newlog):
	global log
	log	=	newlog

# ====================================================================
def Log(level, msg):
	if level > loglevel:
		return
	log.write(msg)

# ====================================================================
def SetLogLevel(level):
	global	loglevel
	loglevel	=	level
